package common

import (
	"fmt"
	"os"
	"os/user"
	"runtime"
	"strings"
)

var appWorkPath string

func init() {
	userHomePath := ""
	if osUser, err := user.Current(); err != nil {
		userHomePath = "./"
	} else {
		userHomePath = osUser.HomeDir
	}

	// 创建 Lucidity Note 的工作目录
	osType := runtime.GOOS
	if strings.EqualFold("linux", osType) || strings.EqualFold("darwin", osType) {
		appWorkPath = fmt.Sprintf("%s/.local/share/lucidity-note/", userHomePath)
	} else if strings.EqualFold("windows", osType) {
		appWorkPath = fmt.Sprintf("%s/AppData/Local/lucidity-note/", userHomePath)
	}
	// 创建目录
	if err := os.MkdirAll(appWorkPath, os.ModePerm); err != nil {
		panic(err)
	}
}

func GetLoggerFilePath() string {
	return fmt.Sprintf("%s/lucidity.note.log", appWorkPath)
}

func GetNustDBDirPath() string {
	return fmt.Sprintf("%s/data/", appWorkPath)
}
